const express = require('express')
const fs = require('fs')
 
var app = express()

var adduser = {
    "user4" : {
        "name":"TomCat",
        "password":"password4",
        "profession":"teacher",
        "id":"4"
    }
}


app.get('/addUser',(req,res) =>{
    fs.readFile(__dirname + '/users.json','utf8',(err ,data) =>{
        if(err){
            console.error(err)
        }else{
            data = JSON.parse(data)
            data["user4"] = adduser["user4"]
            console.log(data)
            res.end(JSON.stringify(data))
            console.log("addUser successfully!")  
        }
     
    })
})

app.listen(8081,() =>{
    console.log('http://localhost:8081/addUser')
})
